#include <cstdio>
#include <cmath>
#include <vector>
#include <glm/glm.hpp>
#include <glm/gtc/noise.hpp>

const int kImageWidth = 1280;
const int kImageHeight = 720;

void ComputeColor(glm::vec4 &out, float x, float y) {
    out = glm::vec4(1.0f);
}

int main(int argc, char *argv[]) {
  std::vector<glm::vec4> image(kImageWidth * kImageHeight);

  for (int j = 0; j < kImageHeight; ++j) {
    for (int i = 0; i < kImageWidth; ++i) {
      float x = (i + 0.5f) / kImageWidth;
      x = (x - 0.5f) * 2.0f * 1.777f;
      float y = (j + 0.5f) / kImageHeight;
      y = (y - 0.5f) * 2.0f;
      ComputeColor(image[j * kImageWidth + i], x, y);
    }
  }

  FILE *fp = std::fopen("skeleton.tga", "wb");
  const unsigned char tga_header[18] = {
    0,0,2,0,0,0,0,0,0,0,0,0, kImageWidth & 0x00ff, (kImageWidth & 0xff00) >> 8,
    kImageHeight & 0x00ff, (kImageHeight & 0xff00) >> 8, 32, 0
  };
  std::fwrite(tga_header, sizeof(tga_header), 1, fp);

  for (int i = 0; i < kImageWidth * kImageHeight; ++i) {
    char rgba[4];
    rgba[0] = static_cast<char>(255.0f * image[i][2]);
    rgba[1] = static_cast<char>(255.0f * image[i][1]);
    rgba[2] = static_cast<char>(255.0f * image[i][0]);
    rgba[3] = static_cast<char>(255.0f * image[i][3]);
    std::fwrite(rgba, sizeof(rgba), 1, fp);
  }

  std::fclose(fp);
  return 0;
}
